package com.xhd.util;

import java.util.Hashtable;
import java.util.Properties;

import com.xhd.base.log.Log;
import com.xhd.base.log.LogFactory;

public class XThread extends Thread {
	public boolean stop = false;
	  private int jm423 = 60;
	  private String jm424 = "";
	  private boolean jm425 = false;
	  private Properties jm144 = new Properties();
	  private static final Log jm9;
	  static Class jm10;

	  static
	  {
	    Class tmp3_0 = jm10;
	    if (tmp3_0 == null)
	    {

	      try
	      {
	        XThread.jm10 = Class.forName("com.xhd.base.util.XThread");
	      }
	      catch (ClassNotFoundException localClassNotFoundException)
	      {
	        throw new NoClassDefFoundError(localClassNotFoundException.getMessage());
	      }
	    }
	    jm9 = LogFactory.getLog(tmp3_0);
	  }

	  public XThread(Runnable paramRunnable)
	  {
	    super(paramRunnable);
	  }

	  public XThread(Runnable paramRunnable, String paramString)
	  {
	    super(paramRunnable, paramString);
	  }

	  public XThread(String paramString)
	  {
	    super(paramString);
	  }

	  public XThread(ThreadGroup paramThreadGroup, Runnable paramRunnable)
	  {
	    super(paramThreadGroup, paramRunnable);
	  }

	  public XThread(ThreadGroup paramThreadGroup, Runnable paramRunnable, String paramString)
	  {
	    super(paramThreadGroup, paramRunnable, paramString);
	  }

	  public XThread(ThreadGroup paramThreadGroup, String paramString)
	  {
	    super(paramThreadGroup, paramString);
	  }

	  protected boolean hasOldThread()
	  {
	    return this.jm425;
	  }

	  protected void stopOldThread()
	  {
	    ThreadGroup localThreadGroup = getThreadGroup();
	    for (int i = 10; (i > 0) && (localThreadGroup.getParent() != null); --i)
	      localThreadGroup = localThreadGroup.getParent();
	    Thread[] arrayOfThread = new Thread[2048];
	    int j = localThreadGroup.enumerate(arrayOfThread, true);
	    if (arrayOfThread == null)
	      return;
	    for (int i = 0; i < j; ++i)
	    {
	      if (arrayOfThread[i] == null)
	        continue;
	      String str = arrayOfThread[i].getName();
	      if ((!(str.equals(getName()))) || (arrayOfThread[i].equals(this)))
	        continue;
	      arrayOfThread[i].interrupt();
	      this.jm425 = true;
	    }
	    arrayOfThread = (Thread[])null;
	  }

	  public void setVaultId(String paramString)
	  {
	    this.jm424 = paramString;
	    setName(getName() + " " + paramString);
	  }

	  public String getVaultId()
	  {
	    return this.jm424;
	  }

	  public void setInterval(int paramInt)
	  {
	    if (paramInt > 0)
	      this.jm423 = paramInt;
	    else
	      this.jm423 = 60;
	  }

	  public int getInterval()
	  {
	    return this.jm423;
	  }

	  public void start()
	  {
	    stopOldThread();
	    if (this.jm425)
	      jm9.info("stop old " + getName());
	    jm9.info("start " + getName());
	    super.start();
	    ThreadMgr.registerThread(this);
	  }

	  public void interrupt()
	  {
	    this.stop = true;
	    super.interrupt();
	    System.out.println("Interrupt " + getName());
	    jm9.info("Interrupt " + getName());
	  }

	  public void wakeUp()
	  {
	    super.interrupt();
	  }

	  public Properties getProperties()
	  {
	    return this.jm144;
	  }

	  public void setProperties(Properties paramProperties)
	  {
	    if (paramProperties == null)
	      this.jm144 = new Properties();
	    else
	      this.jm144 = paramProperties;
	  }

	  public void setProperties(Hashtable paramHashtable)
	  {
	    this.jm144 = new Properties();
	    if (paramHashtable == null)
	      return;
	    this.jm144.putAll(paramHashtable);
	  }

	  public String setProperty(String paramString1, String paramString2)
	  {
	    String str = null;
	    if (paramString1 != null)
	    {
	      str = this.jm144.getProperty(paramString1);
	      if (paramString2 == null)
	        this.jm144.remove(paramString1);
	      else
	        this.jm144.setProperty(paramString1, paramString2);
	    }
	    return str;
	  }

	  public String getProperty(String paramString)
	  {
	    return this.jm144.getProperty(paramString);
	  }
}
